import {ElLoading} from "element-plus";

let loading  = ElLoading.service({
    lock: true,
    text: 'Loading',
    background: 'rgba(0, 0, 0, 0.7)',
});
//声明一个对象用于存储请求个数
let needLoadingRequestCount = 0;

export function startLoading() {
    needLoadingRequestCount++;
    setTimeout(() => {
        loading.close()
    }, 1000)
}

export function endLoading() {
    loading.close();
}

//开启Loading
export function showFullScreenLoading() {
    if (needLoadingRequestCount === 0) {
        startLoading();
    }

}
//关闭Loading
export  function tryHideFullScreenLoading() {
    if (needLoadingRequestCount <= 0) return;
    needLoadingRequestCount--;
    if (needLoadingRequestCount === 0) {
        endLoading();
    }

}
